﻿using System.Web.Mvc;

namespace FoodBank.Web
{
    public class ProviderConfig
    {
        public static void Register()
        {
            RegisterModelValidationProvider();
        }

        private static void RegisterModelValidationProvider()
        {
            // Remove the default ClientDataTypeModelValidatorProvider
            foreach (ModelValidatorProvider prov in ModelValidatorProviders.Providers)
            {
                if (prov.GetType() == typeof(ClientDataTypeModelValidatorProvider))
                {
                    ModelValidatorProviders.Providers.Remove(prov);
                    break;
                }
            }
            // Add our own of the above with a custom messages!
            ModelValidatorProviders.Providers.Add(new FoodBankClientDataTypeModelValidatorProvider());
        }
    }
}